#ifndef IDATAMODELTYPEDEF_H
#define IDATAMODELTYPEDEF_H

/* // 这种方式不行：
#include <tuple>

// name: struct名字
// fields: 成员定义，如 "int a; std::string b;"
// ties:    成员名逗号分隔，如 a,b
#define DEF_MODEL(name, fields, ties)                             \
    struct name {                                                 \
        fields                                                    \
        bool operator==(const name& other) const {                \
            return std::tie(ties) == std::tie(other);             \
        }                                                         \
        bool operator!=(const name& other) const {                \
            return !(*this == other);                             \
        }                                                         \
    };
*/


// 展开成 “type member;”
#define STRUCT_MEMBER(__type, __member) __type __member;

// 展开成 “member == other.member &&”
#define STRUCT_COMPARE(__type, __member) (this->__member == __other.__member) &&

// 定义 DEF_MODEL(name, FIELDS)
#define DEF_MODEL(name, FIELDS)                           \
struct name {                                             \
    FIELDS(STRUCT_MEMBER)                                 \
    bool operator==(const name& __other) const {          \
        return                                            \
            FIELDS(STRUCT_COMPARE) true;                  \
    }                                                     \
    bool operator!=(const name& __other) const {          \
        return !(*this == __other);                       \
    }                                                     \
};

/*  // 使用方法：
#define PERSON_FIELDS(X) \
    X(int,    age)       \
    X(double, weight)    \
    X(const char*, name)

DEF_MODEL(Person, PERSON_FIELDS)
*/
#endif // IDATAMODELTYPEDEF_H
